package com.sq.auth.domain.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.sq.auth.common.enums.AuthUserStatusEnum;
import com.sq.auth.common.enums.IsDeletedFlagEnum;
import com.sq.auth.domain.bo.AuthRoleBO;
import com.sq.auth.domain.bo.AuthUserBO;
import com.sq.auth.domain.service.AuthRoleDomainService;
import com.sq.auth.domain.service.AuthUserDomainService;
import com.sq.auth.infra.basic.entity.AuthRole;
import com.sq.auth.infra.basic.entity.AuthUser;
import com.sq.auth.infra.basic.service.AuthRoleService;
import com.sq.auth.infra.basic.service.AuthUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author quan
 */
@Service
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {

    @Resource
    private AuthRoleService authRoleService;

    @Override
    public boolean add(AuthRoleBO authRoleBO) {
        AuthRole authRole = BeanUtil.copyProperties(authRoleBO, AuthRole.class);
        authRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        int insert = authRoleService.insert(authRole);
        return insert > 0;
    }

    @Override
    public boolean update(AuthRoleBO authRoleBO) {
        AuthRole authRole = BeanUtil.copyProperties(authRoleBO, AuthRole.class);
        int update = authRoleService.update(authRole);
        return update > 0;
    }

    @Override
    public boolean delete(AuthRoleBO authRoleBO) {
        AuthRole authRole = new AuthRole();
        authRole.setId(authRoleBO.getId());
        authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        int delete = authRoleService.update(authRole);
        return delete > 0;
    }
}
